package com.zmc.order.exception.handler;

import com.zmc.common.utils.R;
import com.zmc.order.exception.OrderCancelException;
import com.zmc.order.exception.OrderNotExistException;
import com.zmc.order.exception.SensitiveWordException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：zmc
 * @Date：2024/11/11 15:27
 */

@ControllerAdvice
@ResponseBody
public class OrderExceptionHandler {

    @ExceptionHandler(value = OrderNotExistException.class)
    public R orderNotExistExceptionHandler(OrderNotExistException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = OrderCancelException.class)
    public R orderCancelExceptionHandler(OrderCancelException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = SensitiveWordException.class)
    public R sensitiveWordExceptionHandler(SensitiveWordException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }
}
